<template>
  <div>
    <span style="font-size: 30px">日志</span>
    <el-table :data="data.list" style="width: 100%" v-loading="loading">
      <el-table-column prop="createDate" label="日期" width="180">
      </el-table-column>
      <el-table-column prop="username" label="用户" width="180">
      </el-table-column>
      <el-table-column prop="ip" label="ip" width="180"> </el-table-column>
      <el-table-column prop="operation" label="操作"> </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="data.page"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="data.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="Number(data.total)"
    >
    </el-pagination>
  </div>
</template>
<script>
import axios from "../api/lug";
export default {
  data() {
    return {
      loading: true,
      currentPage: 4,
      data: {},
    };
  },
  methods: {
    getLog(page, pageSize) {
      this.loading = true;
      axios
        .getLog(page, pageSize)
        .then((res) => {
          this.loading = false;
          if (res.data.code == 20000) {
            console.log(res.data.page.list[0]);
            this.data = res.data.page;
          } else {
            this.$message.error(res.data.msg);
          }
        })
        .catch((error) => {
          this.loading = false;
          this.$message.error(error.message);
        });
    },
    handleSizeChange(val) {
      this.getLog(this.data.page, val);
    },
    handleCurrentChange(val) {
      this.getLog(val, this.data.pageSize);
    },
  },
  mounted() {
    this.getLog();
  },
};
</script>